package com.unb.mobilehandover.visao;

import com.example.myfirstapplication.R;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.CellSignalStrengthGsm;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.TextView;

public class SignalStrengthActivity  extends Activity {
	
 SignalStrengthListener signalStrengthListener;
 TextView signalStrengthTextView;


 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
	    
   //setup content stuff
   this.setContentView(R.layout.activity_signal_strength);
   signalStrengthTextView = (TextView)findViewById(R.id.signalStrengthTextView);

   //start the signal strength listener
  signalStrengthListener = new SignalStrengthListener();	           
   ((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).listen(signalStrengthListener,SignalStrengthListener.LISTEN_SIGNAL_STRENGTHS);
 }


 private class SignalStrengthListener extends PhoneStateListener
 {
  @Override
  public void onSignalStrengthsChanged(android.telephony.SignalStrength signalStrength) {
    
     // get the signal strength (a value between 0 and 31)
     int strengthAmplitude = signalStrength.getGsmSignalStrength();
     int strengthAmplitudeAsDBM = strengthAmplitude * 2 - 113;
    
	    //do something with it (in this case we update a text view)
	    signalStrengthTextView.setText("Nivel de sinal GSM: " + String.valueOf(strengthAmplitudeAsDBM));		
	    super.onSignalStrengthsChanged(signalStrength);
	  }
   }
}